import cv2
import numpy as np
from keras import Sequential
from keras.models import load_model
from Face_Recognize.capture_face import CaptureFace


if __name__ == '__main__':
	_model = Sequential()
	MODEL_PATH = 'face_model.h5'
	_model = load_model(MODEL_PATH)
	# print(_model)
	cap = CaptureFace()
	cap.get_face()
	faces = cap.faces
	image = cap.image
	for (x, y, width, height) in faces:
		img = image[y:y + height, x:x + width]
		img = cap.reset_size(image=img)
		img = img.reshape((1, 100, 100, 3))
		img = np.asarray(img, dtype=np.float32)
		img /= 255.0
		result = _model.predict_classes(img)
		cv2.rectangle(image, (x, y), (x + width, y + height), (0, 255, 0), 2)
		font = cv2.FONT_HERSHEY_SIMPLEX
		print(" 结果：", result[0])
		if result[0] == 15:
			cv2.putText(image, 'TEST', (x, y - 2), font, 0.7, (0, 255, 0), 2)
		else:
			cv2.putText(image, 'No.%d' % result[0], (x, y - 2), font, 0.7, (0, 255, 0), 2)
		cv2.imshow('', image)
		cv2.waitKey(0)

